#ifndef SHELL_H
#define SHELL_H

#include <string>
#include <map>
#include <functional>
#include <thread>
#include <vector>
#include <mutex>
#include <atomic>
#include <condition_variable>

namespace El {
namespace Common {

class Shell {
public:
    using CommandFunction = std::function<void(const std::string &)>;

    static Shell &GetInstance();
    void RegisterCommand(const std::string &name, CommandFunction command);
    void Start();
    void Stop();

private:
    Shell();
    ~Shell();

    Shell(const Shell &) = delete;
    Shell &operator=(const Shell &) = delete;
    Shell(Shell &&) = delete;
    Shell &operator=(Shell &&) = delete;

    std::map<std::string, CommandFunction> m_commands;
    static std::vector<std::string> s_command_names;
    std::thread m_thread;
    std::atomic<bool> m_running;
    std::mutex m_mutex;
    std::condition_variable m_cv;

    static char *CommandGenerator(const char *text, int state);
    static char **CommandCompletion(const char *text, int start, int end);
    void ProcessCommand(const std::string &input);
    void RunShell();
    void RegisterDefaultCommands(); // 新增的方法声明
};

} // namespace Common
} // namespace El
#endif // SHELL_H